package com.seven.search;

import java.net.InetAddress;
import java.net.UnknownHostException;

import org.elasticsearch.client.transport.TransportClient;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.transport.InetSocketTransportAddress;
import org.elasticsearch.transport.client.PreBuiltTransportClient;

public class ElasticSearchClient {

	private TransportClient client;
	
	public TransportClient getClient() {
		return client;
	}

	@SuppressWarnings("resource")
	public ElasticSearchClient(){
		Settings setting = Settings.builder().
				// 设置集群的名字
						put("cluster.name", "my-application").
						// 可以动态的添加集群的节点和删除集群的节点
						put("client.transport.sniff", true).build();
		try {
			client = new PreBuiltTransportClient(setting).addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName("192.168.88.244"), 9300));
		} catch (UnknownHostException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
}
